home *** CD-ROM | disk | FTP | other *** search
/ Commodore Free 27 / Commodore_Free_Issue_27_2009_Commodore_Computer_Club.d64 / beginning 12-1 < prev    next >
Text File  |  2023-02-26  |  11KB  |  415 lines

  1. ..
  2.     In the Beginning Part 12
  3.      Lord Ronin from Q-Link
  4.  
  5. Sound was a bit short for my
  6. rambling prattle, the problem was I
  7. ran out of lines as well as workable
  8. examples for the different C=
  9. machines. I mentioned that there are
  10. programmes to make sounds and music
  11. for you, there are also many books to
  12. teach you more on the subject of
  13. music. What I didn't mention is that
  14. in the users manual has data for the
  15. notes all 124, along with other
  16. information for their use.
  17.  
  18. We are now at page 91, moving into
  19. Advanced Data Handling. Time has past
  20. since that last sentence and now; my
  21. directory said that at that time
  22. there were just three blocks written
  23. in this section. While there are
  24. around 13 pages in the Commodore
  25. Users Guide left to handle before the
  26. appendices. Going over the
  27. information in that last section,
  28. before writing my editorial comments
  29. to the material. Man they jumped
  30. through the stuff faster than I did
  31. with the sound section. This might
  32. scare you, and so might the titles of
  33. the topics covered. Read and Data,
  34. Averages, Subscripted Variables, One
  35. dimension arrays, Averages revisited,
  36. Dimension, Simulated dice roll with
  37. arrays and Two dimensional arrays.
  38.  
  39. Alien and scary terms, when I went
  40. through it the first time I was
  41. scared myself. Scares some of the
  42. locals as well when they see the
  43. information, and not just for the
  44. first time. Yet the authors crammed
  45. that information into about 13 pages.
  46.  
  47. What we are going to do now is cover
  48. that information, along with my
  49. comments on my experiences in the use
  50. of these sections. Including things
  51. that we have done, tried to do and
  52. want to do in programming.
  53.  
  54. READ DATA is the first thing
  55. presented on page 92. Doing that
  56. sprite program we had the start of
  57. with Read Data. Type in the following
  58. little program, It will give an error
  59. msg. But that is a part of the
  60. lesson.
  61.  
  62. 10 readx
  63. 20 ?"x is now : ";x
  64. 30 goto10
  65. 40 data 1,34,10.5,16,234,56
  66.  
  67. You can see that it is going to read
  68. the x variable. Then print it in that
  69. X IS NOW : print statement. Got that
  70. loop in 30. On screen you see that it
  71. prints the value of X as each one of
  72. the data entries on line 40. Then
  73. gives "? OUT OF DATA ERROR IN 10".
  74.  
  75. Each time it loops through the X
  76. part of the read. A pointer is given
  77. by the computer to keep track of the
  78. value to be used next. In this
  79. program the loop keeps going till
  80. there is not a single part in the
  81. data statement to use. So it is OUT
  82. OF DATA. That error is in line 10,
  83. this is Because there isn't anything
  84. more for it for it to read, as
  85. ordered in line 10. Well that is
  86. nice, but a bit useless, and I have
  87. seen many programmes give me that
  88. same error. A handful I have been
  89. able to fix. No not ones that I typed
  90. in, ones that came on disks to me
  91. written in Basic.
  92.  
  93. Parts of the DATA statement to
  94. understand. You have Got to start the
  95. line off with the word DATA. OK you
  96. can write it as dA for the shorthand.
  97. Each part of the line of information
  98. must be separated by a comma. This
  99. thinggy here , and nothing else. The
  100. Program will crash with different
  101. error message to you. If you use any
  102. other symbols, Or it may give you a
  103. wrong data read out.
  104.  
  105. Now then what can go into a DATA
  106. statement line? Most of what we have
  107. dealt with already. Integer numbers,
  108. real numbers, you remember the ones
  109. with the numbers to the right of the
  110. decimal point. Number in scientific
  111. notation. You can even put in words
  112. as well. But you CAN'T put in other
  113. variables or math functions. DATA
  114. Z$,12+5,6/3,5*5 is RIGHT OUT!! Not
  115. going to happen as you would like.
  116.  
  117. Next type in is a little different
  118. because it uses afor next loop to
  119. keep that out of data error off the
  120. screen.
  121.  
  122. new
  123.  
  124. 10 forx=1to3
  125. 15 reada$
  126. 20 ?"a$ is now : ";a$
  127. 30 next
  128. 40 data i, did, this
  129.  
  130. Yeah it will print out each line,
  131. going down the screen saying what a$
  132. is each time. What happens if you add
  133.  
  134. 50 goto10
  135.  
  136. Right the return to 10 starts the
  137. program back but you are going to get
  138. the out of data error message, not a
  139. good thing; So in order to reuse the
  140. data just add this line.
  141.  
  142. 45 restore
  143.  
  144. You don't get the out of data, and
  145. the program keeps going on forever.
  146. What happens is that the data pointer
  147. is restored each time through. Not a
  148. big thing at this time for you to
  149. follow.
  150.  
  151. Next is a more practical programme
  152. for read/data.
  153.  
  154. new
  155.  
  156. 10 t=0:ct=0
  157. 20 ifx=-1then50
  158. 25 ct=ct+1
  159. 30 t=t+x
  160. 40 goto10
  161. 50 ?"there were ";ct;"values read"
  162. 60 ?"total = ";t
  163. 70 ?"average =";t/ct
  164. 80 data 75,80,62,91,87,93,78,-1
  165.  
  166. You can probably guess what is going
  167. to happen in some degree. Programme
  168. is going to read all the data and
  169. then print out the number of values
  170. read. In this case it is 7 then by
  171. the math in line 70 the program
  172. prints the average after printing the
  173. total. Here the total is 566 and the
  174. average is 80.8571429.
  175.  
  176. The print statements are easy to
  177. see. Setting the T and CT variables
  178. to 0 at the start is simple. In fact
  179. just about all of what we see in that
  180. program is stuff we have done
  181. already, everything except; there is
  182. this strange thing in line 20 about a
  183. -1. Also in line 80 is that -1 at the
  184. end of the data statement line what
  185. does that one mean? They call it a
  186. flag, it is the indicator that the
  187. read/data part is over. The Program
  188. sees that -1 and then goes to line
  189. 50. Where it does the print and math
  190. work. Line 20 is the check for that
  191. flag of -1. No it doesn't have to be
  192. a -1 in your programme. Can be
  193. anything that isn't a part of what
  194. you are placing in the data
  195. statement, I have seen words and
  196. strange numbers used in some type in
  197. programmes. Anything that is out of
  198. sorts with the theme of your
  199. programme can be used for a flag. You
  200. can make a large collection of data
  201. statements, several lines worth, and
  202. not worry about the count thing. When
  203. using this flag concept.
  204.  
  205. Now here is the last part they give
  206. on the read/data part, showing how to
  207. assign data to a variable.
  208.  
  209. new
  210.  
  211. 10 read n$,a,b,c
  212. 20 ?n$;"'s scores were: ";a;" ";b"
  213. ";c
  214. 30 ?"and the average is: ";(a+b+c)/3
  215. 40 ?:goto10
  216. 50 data
  217. mike,190,185,165,dick,225,245,190
  218. 60 data
  219. john,155,185,205,paul,160,179,187
  220.  
  221. Running this and you will get
  222. something like...
  223.  
  224. mike's scores were: 190 185 165
  225. and the average is : 180
  226.  
  227. Then the other three follow below
  228. that one. Difference in this one is
  229. that the order to be read is set in
  230. line 10. Starting with n$ <name
  231. string> and following with three sets
  232. of variables for the integers. This
  233. data is written in the data statement
  234. lines in the same manner a text and
  235. then the numbers.
  236.  
  237. Small little program that is to give
  238. a basic understanding of how this
  239. works. Obviously it can be bigger and
  240. things like entering the data from a
  241. programme can be done as well. I have
  242. seen read/data statements in many a
  243. Basic programs that I saved from
  244. Q-Link. The first one that I tried to
  245. work upon was an Inn Menu for Fantasy
  246. Role Playing games. Altering the text
  247. to fit different games I messed it up
  248. royally. You see I didn't understand
  249. the concepts of the flag and the read
  250. a certain amount of data Or the point
  251. about correctly placing in text in
  252. the text area and numbers in the
  253. number area. Now that I have learned
  254. more I really should try that project
  255. again.
  256.  
  257. Subscripted Variable, is the next
  258. part; ends right after that above
  259. program. Don't let the words freak
  260. you out. May not have been the best
  261. choice of terms to use for this type
  262. of variable. What this leads into is
  263. one of the mega important parts of
  264. Basic programming, at least from the
  265. part that my group is trying to do at
  266. this time. I'll talk a bit on that
  267. later.
  268.  
  269. Variables we have seen are like F$,
  270. F%, F. Covering the text integer and
  271. real numbers with the floating
  272. decimal. We also learned that you can
  273. have two characters for a variable.
  274. Like F1$, F1%, F1. Or FA$, FA%, and
  275. FA. That can give us a mess of
  276. variables. Little slots of memory
  277. that we can fill in with things. Now
  278. we are going to expand upon that
  279. idea.
  280.  
  281. Z(1) is a new thing. Got that the Z
  282. is the variable. What then is the (1)
  283. part? That is the subscripted
  284. section. Even tells us how to say it
  285. as "Z sub 1". Really this is
  286. different than Z1 or even Z. Z(1) is
  287. subscripted. Yeah I know first time
  288. through this is confusing. They give
  289. a chart thing to try to show you what
  290. they mean. Looks something like this,
  291.  
  292. Z(0)    
  293.  
  294. Z(1)    
  295.  
  296. Z(2)    
  297.  
  298. Z(3)    
  299.  
  300. Z(4)    
  301.  
  302. As an attempt to show you the memory
  303. aspects of a subscripted variable.
  304. The way that I see it is that there
  305. is in the above 5 <0-4> slots in the
  306. variable Z. Slots that something can
  307. be put into.
  308.  
  309. 10 Z(0)=25:Z(3)=55:Z(4)=-45.5
  310.  
  311. A modified form of what they present
  312. next, as a way to see the thing about
  313. putting stuff into those slots.
  314. Modifying the boxes again, it would
  315. look sort of like this in the memory
  316. for Z.
  317.  
  318. Z(0)  25  
  319.    
  320. Z(1)      
  321.    
  322. Z(2)      
  323.  
  324. Z(3)  55  
  325.  
  326. Z(4) -45.3
  327.    
  328.  
  329. Personally I like the effect of the
  330. expanding box to illustrate the fact
  331. that the size isn't set to just one
  332. or two characters.
  333.  
  334. New word now, ARRAY. A group of
  335. subscripted variables is called an
  336. array. This one is a one dimensional
  337. one. You can make multidimensional
  338. arrays as well. Mind boggling isn't
  339. it? Gets even more so, as you can be
  340. more complex by adding other
  341. variables or "computations". These
  342. are CORRECT subscripted variables.
  343.  
  344. Z(X)  Z(X+1)  Z(2+1)  Z(1*3)
  345.  
  346. Got that? Well it is still weak for
  347. me. Point is that here we have a lot
  348. more power than expected for our PC.
  349. Even if you don't programme, you can
  350. see now that we have more than people
  351. think we have, these days. Now add to
  352. this what we have seen already.
  353. Couple this sort of subscripted
  354. variable with things like Input and
  355. Read statements. Right it is past us
  356. at this time. They don't even try to
  357. explain the how it is done part, only
  358. mention it on page 97. New type in
  359. program for you.
  360.  
  361. new
  362.  
  363. 5 ?"<shift clear home>"
  364. 10 input"how many numbers :";x
  365. 20 fora=1tox
  366. 30 ?"enter value # ";a;:inputb(a)
  367. 40 next
  368. 50 su=0
  369. 60 fora=1tox
  370. 70 su=su+b(a)
  371. 80 next
  372. 90 ?:?"average = ";su/x
  373.  
  374. Right it wants to know how many
  375. numbers you are going to insert. Then
  376. it will have you enter each one.
  377. Printing it to the screen. Finally it
  378. will give you the average of all the
  379. numbers.
  380.  
  381. When you run this I want you to say
  382. that you want 5 numbers and the
  383. numbers that you type in will be 125
  384. 167 189 167 158. The reason for this
  385. will be shown a few paragraphs below.
  386. These are the numbers that are
  387. presented in the Commodore users
  388. guide.
  389.  
  390. We have x as the counter for the
  391. loop. The values are entered and go
  392. into the subscripted variable of b.
  393. Every time it loops through the
  394. variable of A is increased. That is
  395. pretty straight forward. Ah but what
  396. is happening is not that straight
  397. forward with what we understand at
  398. this point. Certainly a is changing.
  399. But not the way we have learned
  400. before. First time through the loop.
  401. We have a=1. OK got that part, the
  402. difference is that it is entered into
  403. the subscripted variable of b. So it
  404. would be written, in the manner of
  405. the boxes above asB(1). Next loop
  406. through thevalue of A=2. This is
  407. entered in the b subscripted variable
  408. looking sort of like B(2) from the
  409. above chart theme thing. this goes on
  410. till the number of entries is
  411. completed.
  412.  
  413.         CONTINUED IN 12-2
  414.  
  415.